using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using MathematicallySafe.HeadCounter.Commands;
using MathematicallySafe.HeadCounter.Data;
using MathematicallySafe.HeadCounter.Data.Common;
using MathematicallySafe.HeadCounter.Data.Models;
using MathematicallySafe.HeadCounter.Services;
using StructureMap;

namespace MathematicallySafe.HeadCounter.ViewModels
{
    public class RaiderViewModel : ViewModelBase
    {
        protected Raider _raider;

        private DelegateCommand _postRaiderCommand;
        private DelegateCommand _postRaiderGearCommand;
        private DelegateCommand _postRaiderAttendanceCommand;

        public Raider Model
        {
            get { return _raider; }
        }

        public string Name
        {
            get { return _raider.Name; }
        }

        public CharacterClass Class
        {
            get { return _raider.Class; }
        }

        public CharacterRace Race
        {
            get { return _raider.Race; }
        }

        public DateTime Joined
        {
            get { return _raider.Joined; }
        }

        public bool IsInactive
        {
            get { return Model.IsInactive; }
            set
            {
                Model.IsInactive = value;
                OnPropertyChanged("IsInactive");
            }
        }

        public RaiderViewModel(Raider raider)
        {
            _raider = raider;
            Initialise();
        }

        #region Post Raider

        public ICommand PostRaiderCommand
        {
            get
            {
                if (_postRaiderCommand == null)
                {
                    _postRaiderCommand = new DelegateCommand(PostRaider);
                }

                return _postRaiderCommand;
            }
        }

        private void PostRaider()
        {
            ObjectFactory.GetInstance<IForumPostingService>().PostRaider(_raider);
        }

        #endregion

        #region Post Raider Gear

        public ICommand PostRaiderGearCommand
        {
            get
            {
                if (_postRaiderGearCommand == null)
                {
                    _postRaiderGearCommand = new DelegateCommand(PostRaiderGear);
                }

                return _postRaiderGearCommand;
            }
        }

        private void PostRaiderGear()
        {
            ObjectFactory.GetInstance<IForumPostingService>().PostRaiderGear(_raider);
        }

        #endregion

        #region Post Raider Attendance

        public ICommand PostRaiderAttendanceCommand
        {
            get
            {
                if (_postRaiderAttendanceCommand == null)
                {
                    _postRaiderAttendanceCommand = new DelegateCommand(PostRaiderAttendance);
                }

                return _postRaiderAttendanceCommand;
            }
        }

        private void PostRaiderAttendance()
        {
            ObjectFactory.GetInstance<IForumPostingService>().PostRaiderAttendance(_raider);
        }

        #endregion

    }
}